import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common'
import { AccountService } from './account.service'
import { CreateAccountDto } from './dto/create-account.dto'
import { UpdateAccountDto } from './dto/update-account.dto'
import { AuthGuard } from '@nestjs/passport'

@Controller('account')
@UseGuards(AuthGuard('jwt'))
export class AccountController {
    constructor(private readonly accountService: AccountService) { }

    @Post()
    create(@Body() createAccountDto: CreateAccountDto) {
        return this.accountService.create(createAccountDto);
    }

    @Get()
    findAll(@Query() urlQuery: { tel: string, status?: string, pageIndex: string, pageSize: string }) {
        const query = {
            tel: urlQuery.tel || undefined,
            status: urlQuery.status ? +urlQuery.status : undefined,
            pageIndex: +urlQuery.pageIndex,
            pageSize: +urlQuery.pageSize
        }
        return this.accountService.findAll(query)
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.accountService.findOne(+id)
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateAccountDto: UpdateAccountDto) {
        return this.accountService.update(+id, updateAccountDto)
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.accountService.remove(+id)
    }

	@Post('password')
    updatePassword(@Body() params: { tel: string, oldPassword: string, newPassword: string }) {
        return this.accountService.updatePassword(params)
    }
}
